import express from "express";
import bodyparser from "body-parser";
import cookieparser from "cookie-parser";
import cookiesession from "cookie-session";
import uuid from "uuid";
import consolidate from "consolidate";
import multer from "multer";
import morgan from "morgan";

let multerObj=multer({dest:"./public/upload"});
let server=express();
server.listen(8081);

//允许所有的文件上传
server.use(express.static("./public"));
server.use(morgan("dev"));
server.use(morgan("combined",{
    stream:require("fs").createWriteStream("./logs/logs.log",{flags:"a"})
}))
server.use(multerObj.any());


server.use(bodyparser.urlencoded({
    extended:true,
    limit:"500mb"
}))
server.use(bodyparser.json());
server.use(bodyparser.text());

server.use(cookieparser("kang"));
server.use(cookiesession({
    genid:function()
    {
        return uuid.v1
    },
    maxAge:20*1000*60,
    secret:"kang"
}))

server.set("view engine","html");
server.set("views","./views");
server.engine("html",consolidate.ejs);

//admin
server.use("/admin",require("./route/admin/adminRouter"));
//index